package com.yao.club.controller;

import com.yao.club.entity.result.ResponseEntity;
import com.yao.club.service.SignService;
import com.yao.club.token.UserToken;
import com.yao.club.utils.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/app/sign")
@Api(value = "签到接口", description = "用户签到接口", tags = "签到模块")
public class SignController {

    @Autowired
    private SignService signService;

    @Autowired
    private HttpServletRequest request;

    @UserToken
    @PostMapping("/signIn")
    @ApiOperation(value = "用户签到", notes = "用户签到并更新积分", httpMethod = "POST")
    public ResponseEntity<Boolean> signIn() {
        String username = (String) request.getAttribute("username");
        if (username == null) {
            return ResponseUtils.failed("用户未登录");
        }
        return signService.signIn(username);
    }
    @UserToken
    @PostMapping("/isSignedInToday")
    @ApiOperation(value = "检查今天是否签到", notes = "检查用户今天是否已签到", httpMethod = "POST")
    public ResponseEntity<Boolean> isSignedInToday() {
        String username = (String) request.getAttribute("username");
        if (username == null) {
            return ResponseUtils.failed("用户未登录");
        }
        return signService.isSignedInToday(username);
    }
}